package cn.wit.tech.controller;

import cn.wit.tech.condition.SearchProjectExerciseCondition;
import cn.wit.utils.pojo.ProjectExercise;
import cn.wit.tech.service.ProjectExerciseService;
import cn.wit.utils.response.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/tech/projectExercise")
@CrossOrigin
@Api(tags = "项目练习")
public class ProjectExerciseController {
    private Logger logger = LoggerFactory.getLogger(ProjectExerciseController.class);

    @Autowired
    private ProjectExerciseService projectExerciseService;

    @PostMapping("/insertProjectExercise")
    @ApiOperation("项目新增")
    public Result insertProjectExercise(@RequestBody ProjectExercise projectexercise){
            return this.projectExerciseService.insert(projectexercise);
    }

    @PostMapping("/deleteByIdExercise")
    @ApiOperation("项目删除")
    public Result deleteByIdExercise(int id){
            return this.projectExerciseService.deleteById(id);
    }

    @PostMapping("/updateByIdProjectExercise")
    @ApiOperation("项目更新")
    public Result updateByIdProjectExercise(@RequestBody ProjectExercise projectexercise){
            return this.projectExerciseService.updateById(projectexercise);
    }

    @GetMapping("/searchProjectExercise/{num}/{size}")
    @ApiOperation(value = "条件搜索项目")
    public Result searchProjectExercise(@PathVariable("num") int num,
                                   @PathVariable("size") int size,SearchProjectExerciseCondition condition){
        IPage<ProjectExercise> page=new Page<>(num,size);
            return this.projectExerciseService.searchPage(page, condition);
    }
}
